<?php
require_once('../vendor/autoload.php');

$server1 = \Ratchet\Client\connect('ws://localhost:7001');
$server2 = \Ratchet\Client\connect('ws://localhost:7002');

$server1->then(function ($conn1) use ($server2) {
    $conn1->on('message', function($msg) use ($server2) {
        echo "Received: {$msg}\n";
        $server2->then(function ($conn2) use ($msg) {
            echo 'forwarding message'."\n";
            $conn2->send($msg);
        });
        //$conn1->close();
    });
    $conn1->send('forwarding connected'."\n");
});